
# Compiler
CC = gcc

# Defines
CFLAGS += -Wall -DNGX_JAVASCRIPT_PREFIX=\"/usr/local/nginx\" \
  -DNGX_JAVASCRIPT_HAVE_FILE \
  -DNGX_JAVASCRIPT_HAVE_MYSQL \
  -DNGX_JAVASCRIPT_HAVE_SQLITE \

# Libraries
NGX_JAVASCRIPT_LIBS += -levent -lpthread -lmozjs -lmysqlclient_r -lsqlite3 -lz -L/usr/local/nginx-javascript/lib

# Includes
NGX_JAVASCRIPT_INCLUDES += \
  -I/usr/local/nginx-javascript/include/js \
  -I/usr/local/nginx-javascript/include/mysql

# Sources
NGX_JAVASCRIPT_SRCS = \
  ngx_javascript_main.c \
  ngx_javascript_fcgi.c \
  ngx_javascript_hash.c \
  ngx_javascript_path.c \
  ngx_javascript_server.c \
  ngx_javascript_client.c \
  ngx_javascript_worker.c \
  ngx_javascript_script.c \
  ngx_javascript_request.c \
  ngx_javascript_module_file.c \
  ngx_javascript_module_mysql.c \
  ngx_javascript_module_sqlite.c \

# Dependencies
NGX_JAVASCRIPT_DEPS = Makefile ngx_javascript.h ngx_javascript_fcgi.h

# Objects
NGX_JAVASCRIPT_OBJS = $(patsubst %.c,%.o,$(NGX_JAVASCRIPT_SRCS))

# Default
all: nginx-javascript-fcgi

# Main
nginx-javascript-fcgi: $(NGX_JAVASCRIPT_DEPS) $(NGX_JAVASCRIPT_SRCS) $(NGX_JAVASCRIPT_OBJS)
	$(CC) $(LDFLAGS) $(NGX_JAVASCRIPT_OBJS) $(NGX_JAVASCRIPT_LIBS) -o $@
	strip -g $@

# Compile
%.o: %.c $(NGX_JAVASCRIPT_DEPS)
	$(CC) $(CFLAGS) $(NGX_JAVASCRIPT_INCLUDES) -c $< -o $@

# Clean
clean:
	rm -f nginx-javascript-fcgi $(NGX_JAVASCRIPT_OBJS)
